class TFJetpackfire extends WeaponFire;

var int HitTimer;
var rotator JetDir;
var tfjettrail streams[2];

/*replication
{
    reliable if (ROLE==ROLE_Authority)
        streams;
}*/

function DoFireEffect()
{
    SetTimer(0.075, true);
}

function StopFiring()
{
    Instigator.AmbientSound = Sound'TFMedia.Bomber.JetpackRegen';

    if(streams[0]!=none) streams[0].Destroy();
    if(streams[1]!=none) streams[1].Destroy();

    SetTimer(0.075, true);
}

simulated function PostBeginPlay()
{
	super.PostBeginPlay();
	HitTimer = 0;
}

function Timer()
{
    if(hittimer>0)
    {
        hittimer=fmax(0, hittimer-1);
        if (Weapon.ClientState == WS_ReadyToFire)
            Weapon.PlayIdle();
        StopFiring();
    }

    if (!bIsFiring)
    {
        if (Weapon.AmmoAmount(0) < Weapon.MaxAmmo(0))
            Weapon.AddAmmo(1,0);
        else if(Instigator.AmbientSound==Sound'TFMedia.Bomber.JetpackRegen')
            Instigator.AmbientSound = none;

    }
    else
    {
        Instigator.AmbientSound = Sound'TFMedia.Bomber.JetpackLoop';
        JetDir=Instigator.Controller.Rotation;
        JetDir.Pitch+=16200;

        if (!Weapon.ConsumeAmmo(0,1))
        {
            if (Weapon.ClientState == WS_ReadyToFire)
                Weapon.PlayIdle();
            StopFiring();
        }
        else
        {
            weapon.Instigator.addvelocity(28 * vector(JetDir));

            //jetdir=rotator(instigator.Velocity);

            if(streams[0]==none)
            {
                streams[0]=spawn(class'taskforces.tfjettrail',instigator,,instigator.location,JetDir);
                Instigator.AttachToBone(streams[0],'rfoot');
            }
            if(streams[1]==none)
            {
                streams[1]=spawn(class'taskforces.tfjettrail',instigator,,instigator.location,JetDir);
                Instigator.AttachToBone(streams[1],'lfoot');
            }

            Instigator.AttachToBone(spawn(class'taskforces.tfjetstream',instigator,,instigator.location,jetdir),'rfoot');
            Instigator.AttachToBone(spawn(class'taskforces.tfjetstream',instigator,,instigator.location,jetdir),'lfoot');

            Instigator.addvelocity(vect(0,0,60));
        }
    }

}

function StartBerserk()
{
}

function StopBerserk()
{
}

defaultproperties
{
     bPawnRapidFireAnim=True
     bWaitForRelease=True
     bModeExclusive=False
     FireAnim=
     FireLoopAnim=
     FireEndAnim="Idle"
     FireSound=Sound'TFMedia.Bomber.JetPackBoost'
     FireForce="TranslocatorModuleRegeneration"
     FireRate=1.000000
     AmmoClass=Class'taskforces.TFJetpackAmmo'
     BotRefireRate=1.000000
}
